package com.googlecode.jerato.library.view;

import java.io.InputStream;

import javax.servlet.ServletContext;

import com.googlecode.jerato.library.SystemService;

public class ViewSystemService extends SystemService{
	protected ServletContext _servletContext; 

	public ViewSystemService(ServletContext context){
		if(context == null){
			throw new IllegalArgumentException();
		}
		_servletContext = context;
	}

	public InputStream getResourceAsStream(String resourcePath){
		InputStream input = null;
		if(_servletContext != null){
			input = _servletContext.getResourceAsStream("WEB-INF/xml/" + resourcePath);
			if(input != null){
				return input;
			}
			input = _servletContext.getResourceAsStream("WEB-INF/classes/" + resourcePath);
			if(input != null){
				return input;
			}
		}
		if(input == null){
			input = ClassLoader.getSystemResourceAsStream(resourcePath);
		}
		return input;
	}

}
